<?php
$db = new SQLite3("students.db");

$res = $db->query("select * from students where id='".$_POST["id"]."'");
$msg = $res->fetchArray(SQLITE3_ASSOC);

$res = $db->query("select course.name as cname, grade from grades left join course on grades.cou_id=course.id where stu_id='".$_POST["id"]."'");
$gradeData = array(); $i = 0;
while ($grade = $res->fetchArray(SQLITE3_ASSOC)) {
    $gradeData[$i]["cname"] = $grade["cname"];
    $gradeData[$i]["grade"] = $grade["grade"];
    $i++;
}
echo json_encode(array($msg, $gradeData));
?>